package top.lossingdawn.antlr4.hello;

import com.alibaba.fastjson.JSON;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;
import top.lossingdawn.antlr4.hello.antlr.HelloBaseVisitor;
import top.lossingdawn.antlr4.hello.antlr.HelloParser;

import java.util.stream.Collectors;

/**
 * @author jiangyj
 * @version 1.0
 * @create 2021-12-10 14:18
 **/
public class HelloProcessor extends HelloBaseVisitor<String> {

    @Override
    public String visit(ParseTree tree) {
        return super.visit(tree);
    }


    @Override
    public String visitMain(HelloParser.MainContext ctx) {
        return JSON.toJSONString(ctx.ID().stream().map(TerminalNode::getText).collect(Collectors.toList()));
    }
}
